define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order/index' + location.search,
                    table: 'learn_course_order',
                }
            });

            var table = $("#table");
            var datetimeFormat = 'YYYY-MM-DD';
            var  stvisible = '=';
            var  stvisible2 = true;
            if(Config.org_cate_id > 0){
                stvisible = false;
                stvisible2 = false;
            }
            table.on('post-common-search.bs.table', function (event, table) {
                $(".commonsearch-table").find('.btn-success').html('搜索');
                $(".commonsearch-table").find('.btn-default').html('刷新');
                $(".columns-right").hide();
                $('.form-commonsearch').attr('autocomplete', 'off');
            });
//当表格数据加载完成时
            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                //这里我们手动设置底部的值
                $("#total_money").text(data.extend.total_money);
                $("#pay_money").text(data.extend.pay_money);
                $("#left_money").text(data.extend.left_money);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                datetimeFormat:'YYYY-MM-DD',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('序号'), operate:false},
                        {field: 'course.org_cate_id', title: __('单位'),visible: false, operate:stvisible, searchList: $.getJSON('usechart/searchlist')},
                        {field: 'oname', title: __('单位'),visible: stvisible2, operate:false},
                        {field: 'order_sn', title: __('Order_sn'), operate:'LIKE'},
                        {field: 'course.number', title: __('课程编码'), operate:'LIKE'},
                        {field: 'course.name', title: __('Course_name'), operate:false},
                        {field: 'price', title: __('销售价格'), operate:false},
                        {field: 'user.id', title: __('购买者ID'), operate:false},
                        {field: 'user.nickname', title: __('购买者昵称'), operate:false},
                        {field: 'createtime', title: __('订单时间'), operate:false, addclass:'datetimerange',formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('订单时间段'),visible:false, operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('订单状态'), operate:false, formatter: Table.api.formatter.normal,searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}},
                        {field: 'usertype', title: __('用户类型'), formatter: Table.api.formatter.normal,searchList: {"1":__('用户'),"2":__('访客')}},
                        {field: 'course.type', title: __('课程类型'), formatter: Table.api.formatter.normal,searchList: {"1":__('总平台'),"2":__('自有')}},

                        {field: 'pay_time', title: __('Pay_time'), operate:false, addclass:'datetimerange',formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormVisible: true,
                search:false,
                onLoadSuccess:function(){
                    // 这里就是数据渲染结束后的回调函数
                    $(".btn-editone").data("area", ["100%","100%"]);
                    $(".columns-right").hide();
                }
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
         add: function () {
             Controller.api.bindevent();
         },
         edit: function () {
             Controller.api.bindevent();
         },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

            }
        }

    };
    return Controller;
});